package com.hhh.Config;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.List;

@Slf4j
@Configuration
public class WebSourceConfig extends WebMvcConfigurationSupport {
//    配置前端网页的映射资源
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        log.info("映射资源");
        registry.addResourceHandler("/backend/**").
                addResourceLocations("classpath:/backend/");
        registry.addResourceHandler("/front/**").
                addResourceLocations("classpath:/front/");
    }

//    增加mvc的消息转化器
    @Override
    protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
//        创建信息转化器
        MappingJackson2HttpMessageConverter messageConverter=new MappingJackson2HttpMessageConverter();
//        转化器使用  对象映射器:基于jackson将Java对象转为json，或者将json转为Java对象
        messageConverter.setObjectMapper(new JacksonObjectMapper());
//        把转化器加入到转化器容器中
        converters.add(0,messageConverter);
    }
}
